<script>
import {inject} from "vue";

export default {
  name: 'SonComponent',
  components: {},
  setup() {
    // 其中 inject 配合 provide 就可以获取到父级组件传递过来的数据
    let car = inject('car');
    console.log(car);
    return {
      car
    }
  }
}
</script>

<template>
  <div class="son">
    <h3>我是 Son 组件【孙组件】</h3>
    <h2>汽车名称：{{ car.name }}</h2>
    <h2>汽车价格：{{ car.price }}</h2>
    <hr>
  </div>
</template>

<style scoped>
.son {
  background: #dab649;
  padding: 20px;
}
</style>